/**
 * FileName: T57
 * Author:   powersi
 * Date:     2021/3/3 16:16
 * Description:
 */
package com.zm.demo.core.leetcode;

import java.util.Stack;

/**
 * Description: 
 * Author:      powersi
 * Date:        2021/3/3 16:16
 */
public class T57 {

    public static void main(String[] args) {
        new T57().findContinuousSequence(15);
    }
        public int[][] findContinuousSequence(int target) {

            Stack<int[]>stack = new Stack<>();
            for(int i = target-1; i>0; i--){
                f(target, i, stack);
            }

            int[][]result = new int[stack.size()][];
            int index = 0;
            while (stack.size()>0){
                result[index++] = stack.pop();
            }
            return result;
        }

        public int[] f(int t, int max,Stack<int[]>stack1){
            Stack<Integer>stack = new Stack<>();
            int sum = 0;
            for(int i = max; i > 0; i--){
                sum+=i;
                if(sum<t){
                    stack.push(i);
                }else if(sum == t){
                    stack.push(i);
                    int[] r = new int[stack.size()];
                    int index = 0;
                    while (stack.size()>0){
                        r[index++] = stack.pop();
                    }
                    stack1.push(r);
                    return r;
                }else{
                    return null;
                }
            }
            return null;
        }
}
